﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using OOS.Application.Category.Dtos;
using OOS.Application.Category.Services.Interfaces;
using OOS.Application.Category.Vos;
using OOS.Core.Category;
using OOS.Core.RelyOn;

namespace OOS.Application.Category
{
    /// <summary>
    /// 分类管理
    /// </summary>
    [Route("[Controller]")]
    public class CategoryBasicAppService:IDynamicApiController
    {
        private readonly ICategoryBasicService _categoryBasicService;

        public CategoryBasicAppService(ICategoryBasicService categoryBasicService)
        {
            _categoryBasicService = categoryBasicService;
        }

        /// <summary>
        /// 新增分类
        /// </summary>
        /// <param name="categoryBasic"></param>
        /// <returns></returns>
        [HttpPost]
        public bool AddCategoryBasic(CategoryBasic categoryBasic)
        {
            return _categoryBasicService.InsertCategoryBasic(categoryBasic);
        }

        /// <summary>
        /// 根据id查询分类详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public CategoryBasicDto GetCategoryBasic(int id)
        {
            return _categoryBasicService.SelectCategoryById(id);
        }

        /// <summary>
        /// 根据Id修改分类信息
        /// </summary>
        /// <param name="categoryBasic"></param>
        /// <returns></returns>
        [HttpPut]
        public bool UpdateCategoryBasic(CategoryBasic categoryBasic)
        {
            return _categoryBasicService.UpdateCategoryBasicById(categoryBasic);
        }

        /// <summary>
        /// 按条件(分类名称模糊查询，分类类型精确查询)分页查询
        /// </summary>
        /// <param name="searchCategoryVo"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public PageResponseDto<List<CategoryBasicDto>> GetCategoryList([FromQuery]SearchCategoryVo searchCategoryVo, int pageIndex, int pageSize)
        {
            CategoryBasic categoryBasic = searchCategoryVo.Adapt<CategoryBasic>();
            return _categoryBasicService.SelectPageByConditions(categoryBasic, pageIndex, pageSize);
        }

        /// <summary>
        /// 根据Id删除分类信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public bool DeleteCategoryBasic(int id)
        {
            return _categoryBasicService.DeleteCategoryBasicById(id);
        }
    }
}
